/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.admin.model;

import com.common.json.JsonModel;
import com.entities.Employee;
import com.entities.EventLibrary;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.StoredProcedureQuery;
import org.json.simple.JSONObject;

/**
 *
 * @author Tuan Long
 */
@Stateless
public class EmployeeFacade extends AbstractFacade<Employee> implements EmployeeFacadeLocal {
    @PersistenceContext(unitName = "BluePumpkinEJBPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public EmployeeFacade() {
        super(Employee.class);
    }

    @Override
    public boolean createEmployee(Employee employee) {
        String username = employee.getUsername();
        String pass = employee.getPassword();
        String email = employee.getEmail();
        String fullname = employee.getFullname();
        String gender = employee.getGender();
        Date birthday = employee.getBirthdate();
        String phone = employee.getPhone();
        String mobile = employee.getMobilephone();
        String address = employee.getAddress();
        String card = employee.getIdentityCard();
        String poistion = employee.getPosition();
        String department = employee.getDepartments();
        String group = employee.getGroups();
        String avatar = employee.getAvatar();        
        StoredProcedureQuery query = em.createNamedStoredProcedureQuery("Employee.createNewEmployee");
        query.setParameter("username",username);
        query.setParameter("password",pass);
        query.setParameter("email",email);
        query.setParameter("fullname",fullname);
        query.setParameter("gender", gender);
        query.setParameter("birthday",birthday);
        query.setParameter("phone", phone);
        query.setParameter("mobile",mobile);
        query.setParameter("address", address);
        query.setParameter("indentitycard", card);
        query.setParameter("position", poistion);
        query.setParameter("department", department);
        query.setParameter("groups", group);
        query.setParameter("avatar", avatar);
        int result = query.executeUpdate();
        return result > 0;
    }

    @Override
    public boolean changeEmployeePassword(String username, String password) {
        StoredProcedureQuery query = em.createNamedStoredProcedureQuery("Employee.changeEmployeePassword");
        query.setParameter("username", username);
        query.setParameter("password", password);
        int result = query.executeUpdate();
        return result > 0;
    }

    
    
}
